<template>
  <div>
    <!-- 添加 trigger 属性，触发方式 -->
    <el-dropdown trigger="click" @command="handleCommand">
      <div>
        <svg-icon style="color:#fff;font-size:20px" icon-class="language" />
      </div>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="zh" :disabled="'zh' === $i18n.locale">中文</el-dropdown-item>
        <el-dropdown-item command="en" :disabled="'en' === $i18n.locale">English</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: 'Lang',
  // data() {
  //   return {
  //     lang: 'en'
  //   }
  // },
  methods: {
    // 点击每一项时触发的方法
    // 形参是 el-dropdown-item 组件的 command 属性的属性值
    handleCommand(command) {
      console.log(this.$i18n.locale)
      this.$i18n.locale = command
      // this.lang = command
      console.log(this.$i18n.locale)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
